package com.charm.frameworkarou.share

import android.os.Bundle
import android.support.design.widget.BottomSheetDialogFragment
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.chad.library.adapter.base.BaseQuickAdapter
import com.charm.frameworkarou.R
import kotlinx.android.synthetic.main.fragment_share.*

class ShareFragment : BottomSheetDialogFragment() {


    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater!!.inflate(R.layout.fragment_share, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        var list: List<ShareEntity> = listOf(ShareEntity(0, "QQ", R.drawable.icon_share),
                ShareEntity(0, "微信", R.drawable.icon_share),
                ShareEntity(0, "微博", R.drawable.icon_share),
                ShareEntity(0, "FaceBook", R.drawable.icon_share)
        )
        var adapter = ShareAdapter(list)
        rv.layoutManager = GridLayoutManager(context, 4) as RecyclerView.LayoutManager?
        rv.adapter = adapter
        adapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { adapter, _, position ->
            var entity = adapter.data[position] as ShareEntity
            Toast.makeText(context, entity.name, Toast.LENGTH_SHORT).show()
        }
    }
}